// Author: combacsa@kaist.ac.kr
// http://www.jungol.co.kr/prog/Hanal/hanalView.php?qs_code=1080

//#define COMPILE
#ifdef COMPILE

#include <fstream>
using namespace std;

int n;
int m;

int answer = 0;
int primes[100];
int primes_count = 0;
bool is_prime[100];

void input() {
	ifstream in("input.txt");
	in >> n >> m;

	in.close();
}

void get_primes() {
	for (int i = 10; i <= 99; i++) {
		bool sosu = true;
		for (int j = 2; j < i; j++) {
			if (i % j == 0)
				sosu = false;
		}
		if (sosu) {
			primes[primes_count++] = i;
			is_prime[i] = true;
		} else
			is_prime[i] = false;
	}
}

bool is_prime_step_2(int chosen, int reminder) {
	if (reminder < 1)
		return false;
	else if (is_prime_step_2(chosen, reminder / 10))
		return true;
	else {
		int n1 = chosen * 10 + reminder % 10;
		int n2 = (reminder % 10) * 10 + chosen;
		if (is_prime[n1] || is_prime[n2])
			return true;
		else
			return false;
	}
}

bool is_prime_step_1(int x) {
	if ( x < 10)
		return false;
	else if (is_prime_step_1(x / 10))
		return true;
	else if (is_prime_step_2(x % 10, x / 10))
		return true;
	else
		return false;
}

void solve() {
	get_primes();
	for (int i = n; i <= m; i++) {
		if (is_prime_step_1(i))
			answer++;
	}
}

void output() {
	ofstream out("output.txt");
	out << answer;
	out.close();
}

int main() {
	input();
	solve();

	output();

	return 0;
}
#endif
